using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using MySql.Data.MySqlClient;
namespace LdExpress
{
    public class OfferPriceQuantity
    {
        public long ID = -1;
        public long OfferPriceID = 0;
        public long CustomerID = 0;
        public string Name = "";
        public string QtySet = "";
        public long Qty = 0;
        public long DC20 = 0;
        public long DC40 = 0;
        public long HC40 = 0;
        public long RF20 = 0;
        public long RF40 = 0;
        public long CBM = 0;
        public long KG = 0;
        public DateTime LastUpdate = DateTime.Now;

        public OfferPriceQuantity()
        {
        }

        public OfferPriceQuantity(long lID)
        {
            this.ID = lID;
        }

        public void Save(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            string strTableName = "tbl_offerpricequantity";


            if (ID <= 0) // new object, we insert new record to database
            {
                strSQL = "Insert into " + strTableName + " (" +
                            "`OfferPriceID`" +
                            ",`CustomerID`" +
                            ",`Name`" +
                            ",`QtySet`" +
                            ",`Qty`" +
                            ",`DC20`" +
                            ",`DC40`" +
                            ",`HC40`" +
                            ",`RF20`" +
                            ",`RF40`" +
                            ",`CBM`" +
                            ",`KG`" +
                            ",`LastUpdate`" +
                            ") " +
                         " values(" +
                             OfferPriceID.ToString() +
                             "," + CustomerID.ToString() +
                             "," + "'" + DBModule.RefineString(Name) + "'" +
                             "," + "'" + DBModule.RefineString(QtySet) + "'" +
                             "," + Qty.ToString() +
                             "," + DC20.ToString() +
                             "," + DC40.ToString() +
                             "," + HC40.ToString() +
                             "," + RF20.ToString() +
                             "," + RF40.ToString() +
                             "," + CBM.ToString() +
                             "," + KG.ToString() +
                             "," + DBModule.RefineDatetime(LastUpdate) +
                             ")";
                // run SQL statement
                //throw new Exception(strSQL);
                DBModule.ExecuteNonQuery(strSQL, cn, trans);
            }
            else // edit object
            {
                // build SQL statement
                strSQL = "Update " + strTableName + " set " +
                    " OfferPriceID= " + OfferPriceID.ToString() +
                    " ,CustomerID= " + CustomerID.ToString() +
                    " ,Name='" + DBModule.RefineString(Name) + "'" +
                    " ,QtySet='" + DBModule.RefineString(QtySet) + "'" +
                      ",Qty = " + Qty.ToString() +
                      ",DC20 = " + DC20.ToString() +
                      ",DC40 = " + DC40.ToString() +
                      ",HC40 = " + HC40.ToString() +
                      ",RF20 = " + RF20.ToString() +
                      ",RF40 = " + RF40.ToString() +
                      ",CBM = " + CBM.ToString() +
                      ",KG = " + KG.ToString() +
                      ",LastUpdate=" + DBModule.RefineDatetime(LastUpdate) + "" +
                    " where ID=" + ID.ToString();
                // run SQL statement
                DBModule.ExecuteNonQuery(strSQL, cn, trans);
            }
            //if (!IsUniqueNameExisting(this.Name, this.ID, con, trans))

        }
        public void Delete(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "DELETE FROM tbl_offerpricequantity WHERE ID = " + this.ID.ToString();
            DBModule.ExecuteNonQuery(strSQL, cn, trans);
        }

        public void Load(MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "SELECT * FROM tbl_offerpricequantity WHERE ID = " + ID.ToString() + " limit 0,1";
            DataSet ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            //Fill data into this object
            if (ds.Tables[0].Rows.Count > 0)
            {
                DataRow dr = ds.Tables[0].Rows[0];
                if (!dr.IsNull("ID")) ID = long.Parse(dr["ID"].ToString());
                if (!dr.IsNull("Name")) Name = dr["Name"].ToString();
                if (!dr.IsNull("QtySet")) QtySet = dr["QtySet"].ToString();
                if (!dr.IsNull("CustomerID")) CustomerID = long.Parse(dr["CustomerID"].ToString());
                if (!dr.IsNull("OfferPriceID")) OfferPriceID = long.Parse(dr["OfferPriceID"].ToString());
                if (!dr.IsNull("DC20")) DC20 = long.Parse(dr["DC20"].ToString());
                if (!dr.IsNull("DC40")) DC40 = long.Parse(dr["DC40"].ToString());
                if (!dr.IsNull("HC40")) HC40 = long.Parse(dr["HC40"].ToString());
                if (!dr.IsNull("RF20")) RF20 = long.Parse(dr["RF20"].ToString());
                if (!dr.IsNull("RF20")) RF20 = long.Parse(dr["RF20"].ToString());
                if (!dr.IsNull("CBM")) CBM = long.Parse(dr["CBM"].ToString());
                if (!dr.IsNull("KG")) KG = long.Parse(dr["KG"].ToString());
                if (!dr.IsNull("LastUpdate")) LastUpdate = DateTime.Parse(dr["LastUpdate"].ToString());
            }
        }
        public void GetList(string strCondition, string OrderBy, int NumOfItemsPerPage, int PageNo, out int NumberOfPages, out DataSet ds, MySqlConnection cn, MySqlTransaction trans)
        {
            NumberOfPages = 0;
            string strSQL = "";
            ds = null;
            // build SQL statement
            strSQL = "Select * from tbl_offerpricequantity where 1=1 ";
            if ((strCondition != null) && (strCondition != ""))
            {
                strSQL += strCondition;
            }
            if ((OrderBy != null) && (OrderBy != ""))
                strSQL += " Order By " + DBModule.RefineString(OrderBy);
            // run SQL statement
            if (NumOfItemsPerPage > 0)
            {
                ds = DBModule.ExecuteQuery(strSQL, NumOfItemsPerPage, PageNo, out NumberOfPages, cn, trans);
            }
            else
                ds = DBModule.ExecuteQuery(strSQL, cn, trans);

        }

        public static void GetListCount(string strCondition, out int nCount, MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            // build SQL statement
            strSQL = "Select ID from tbl_offerpricequantity where 1=1 ";
            if ((strCondition != null) && (strCondition != ""))
            {
                strSQL += strCondition;
            }
            DataSet ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            if (ds.Tables[0].Rows.Count > 0)
                nCount = ds.Tables[0].Rows.Count;
            else
                nCount = 0;

        }
        public static void GetListCount(string strCondition, out int nCount, out long nID, MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            // build SQL statement
            strSQL = "Select ID from tbl_offerpricequantity where 1=1 ";
            if ((strCondition != null) && (strCondition != ""))
            {
                strSQL += strCondition;
            }
            DataSet ds = DBModule.ExecuteQuery(strSQL, cn, trans);
            if (ds.Tables[0].Rows.Count > 0)
            {
                nCount = ds.Tables[0].Rows.Count;
                nID = long.Parse(ds.Tables[0].Rows[0]["ID"].ToString());
            }
            else
            {
                nCount = 0;
                nID = 0;
            }

        }

        public void DoSearch(string strKeywords, string OrderBy, out DataSet ds, MySqlConnection cn, MySqlTransaction trans)
        {
            string strSQL = "";
            ds = null;
            // build SQL statement
            strSQL = "Select `ID` from tbl_offerpricequantity where 1=1 ";

            if ((OrderBy != null) && (OrderBy != ""))
                strSQL = strSQL + " Order By " + DBModule.RefineString(OrderBy);
            // run SQL statement
            ds = DBModule.ExecuteQuery(strSQL, cn, trans);
        }

    }
}


